<?php
namespace Cck\ArticlesSystem\Http\Models;

use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;

/**
 * 文章关键词
 * @property integer $user_id
 * @property integer $tag_id
 * @property integer $keyword_id
 * @property string $keyword
 * @property Carbon|null $used_at
 * @property integer $operator_keyid
 * 
 * @property-read User $owner
 * @property-read Article[]|Collection $articles
 */
class Keyword extends Model
{
    protected $table = 'keywords';

    protected $fillable = [
        'user_id', 'tag_id', 'keyword_id', 'keyword', 'used_at', 'operator_keyid'
    ];

    protected $dates = [
        'used_at'
    ];

    protected $casts = [
        'user_id' => 'integer',
        'tag_id' => 'integer',
        'keyword_id' => 'integer',
        'operator_keyid' => 'integer'
    ];

    public function owner()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function articles()
    {
        return $this->hasMany(Article::class, 'keyword_id', 'id');
    }
}
